package com.tpln.service.impl;

import com.tpln.mapper.NodeMapper;
import com.tpln.pojo.NodeInfo;
import com.tpln.service.NodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.soap.Node;
import java.util.List;

@Service
public class NodeServiceImpl implements NodeService {
    @Autowired
    private NodeMapper nodeMapper;

    @Override
    public boolean addNode(String nodeTitle, String nodeContent,String userId) {

        int addCount = nodeMapper.addNode(nodeTitle,nodeContent,userId);
        if(addCount > 0){
            return true;
        }
        return false;
    }

    @Override
    public List<NodeInfo> selectNodeInfoByUserId(String userId) {
        List<NodeInfo> nodeInfos = nodeMapper.selectNodeInfoByUserId(userId);
        for (int i=0; i< nodeInfos.size(); i++){
            nodeInfos.get(i).setNodeContent(nodeInfos.get(i).getNodeContent().replaceAll("[^\u4E00-\u9FA5]",""));
        }
        return nodeInfos;
    }

    @Override
    public NodeInfo selectNodeInfoByNodeId(String nodeId) {
        NodeInfo nodeInfo = nodeMapper.selectNodeInfoByNodeId(nodeId);
        return nodeInfo;
    }

}
